package dujiu.leetcode.slidingWindow.fixed_lengthSlidingWindow;

public class P2379 {
    public int minimumRecolors(String blocks, int k) {
        char[] chars = blocks.toCharArray();
        int ans = 0; // 最小操作次数
        int res = Integer.MAX_VALUE;
        int n = blocks.length();
        for (int i = 0; i < blocks.length(); i++) {
            if (chars[i] == 'W'){
                ans++;
            }
            if (i<k-1){
                continue;
            }
            res = Math.min(res,ans);
            char out = chars[i-k+1];
            if (out == 'W'){
                ans--;
            }
        }
        return ans;
    }
}
